import { GCellRenderer } from "../../../../com/mui/controls/GCellRenderer";
import { GTextFormat } from "../../../common/GTextFormat";
import { BaseItem } from "../common/BaseItem";
import { NumberTool } from "./NumberTool";
import { GButton } from "../../../../com/mui/controls/GButton";
import { Language } from "../../../../extend/language/Language";
import { ObjCreate } from "../common/ObjCreate";
import { ImagesConst } from "../../resource/ImagesConst";
import { SRunBusinessItemBuy } from "../../../../Message/Public/SRunBusinessItemBuy";
import { ItemData } from "../../resource/info/ItemData";
import { Cache } from "../../cache/Cache";
import { ItemConfig } from "../../resource/ItemConfig";
import { Dispatcher } from "../../../mvc/core/Dispatcher";
import { DataEvent } from "../../events/DataEvent";
import { EventName } from "../../mvc/EventName";
import { _itemCode } from "../../../../this/_itemCode";
type int = number;
//class ShopGoodsRenderer
    
    export  class ShopGoodsRenderer extends GCellRenderer
    {
        constructor()
        {
            super();
            return;
        }

        protected /* override */ configUI(): void
        {
            this._blueTf = new GTextFormat("", 12, 11661311);
            this._item = new BaseItem();
            this._item.setSize(30, 30);
            this._item.move(0, 1);
            this._item.setAmountLabelPos(0, 16);
            addChild(this._item);
            this._goodsName = this.createTextfield(35, 5, 60, 20, "", this._blueTf);
            this._unitPriceSell = this.createTextfield(100, 5, 60, 20, "", this._blueTf);
            this._numberTool = new NumberTool();
            this._numberTool.x = 155;
            this._numberTool.y = 5;
            this._numberTool.maxNumber = 99;
            addChild(this._numberTool);
            this._buyBtn = new GButton();
            this._buyBtn.setSize(38, 22);
            this._buyBtn.move(190, 5);
            this._buyBtn.label = Language.getString(35309);
            this._buyBtn.styleName = "Button";
            this._buyBtn.drawNow();
            this._buyBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onBuyBtnClickHandler);
            addChild(this._buyBtn);
            var loc1=ObjCreate.createBg(0, 32, 230, 2, this, ImagesConst.SplitLine);
            return;
        }

        /* internal  */createTextfield(arg1: int, arg2: int, arg3: int, arg4: int, arg5: string, arg6: Object /* flash.text.TextFormat */): Object /* flash.text.TextField */
        {
            var loc1=null;
            (loc1 = new Object /* flash.text.TextField */()).x = arg1;
            loc1.y = arg2;
            loc1.width = arg3;
            loc1.height = arg4;
            loc1.text = arg5;
            loc1.selectable = false;
            loc1.mouseEnabled = false;
            loc1.setTextFormat(arg6);
            addChild(loc1);
            return loc1;
        }

        public /* override */ set data(arg1: Object)
        {
            super.data = arg1;
            var loc1=arg1 as SRunBusinessItemBuy;
            this._itemCode = loc1.itemCode;
            var loc2=new ItemData(this._itemCode);
            this._item.itemData = loc2;
            var loc3;
            var loc4;
            var loc5;
            if ((loc5 = (loc4 = (loc3 = Cache.instance.runBusiness.getSliverNoteItemData()).itemExInfo.rb_value) / loc1.buyPrice) < 99) 
            {
                this._numberTool.maxNumber = loc5;
                this._numberTool.currentNumber = loc5;
            }
            else 
            {
                this._numberTool.maxNumber = 99;
                this._numberTool.currentNumber = 99;
            }
            var loc6=ItemConfig.instance.getInfoByCode(loc2.itemCode).item.name;
            this._goodsName.text = loc6;
            this._goodsName.setTextFormat(this._blueTf);
            this._unitPriceSell.text = loc1.buyPrice.toString();
            this._unitPriceSell.setTextFormat(this._blueTf);
            return;
        }

        /* internal  */onBuyBtnClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.RunBusinessBuyGoods, {"itemCode": _itemCode, "amount": this._numberTool.number}));
            return;
        }

        /* internal */ /* var */_blueTf: Object /* flash.text.TextFormat */;

        /* internal */ /* var */_item: BaseItem;

        /* internal */ /* var */_goodsName: Object /* flash.text.TextField */;

        /* internal */ /* var */_unitPriceSell: Object /* flash.text.TextField */;

        /* internal */ /* var */_numberTool: NumberTool;

        /* internal */ /* var */_buyBtn: GButton;

        /* internal */ /* var */_itemCode: int;
    }
